#include<time.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
    int tol = 0;
    printf("\n * * * * * * * catch thirty * * * * * * *\n");
    printf("Game Begin\n");
    //randomize();
    if( random()%2 == 1 )
    tol = input(tol) ;
    while( tol != 30)   
        if((tol = copu(tol)) ==30)
        printf("You lose!\n");
        else
        if(( tol = input(tol)) == 30)
        printf("I lose! \n");
        printf(" * * * * * * * * * Game Over * * * * * * * *\n");
}
int input(int t)
{
    int a;
    do{
        printf("Please count:");
        scanf("%d",&a);
        if( a>2 || a<1 || t+a > 30)
        printf("Error input,again! ");
        else
        printf("You count: %d \n",t+a);
    }while ( a>2 || a<1 || t+a > 30 );
    return (t+a);
}
int copu(int s)
{
    int c;
    printf(" Computer count:");
    if(( s+1 ) %3 == 0 )
        printf(" %d\n",++s);
    else if(( s+2 ) %3 == 0)
    {
        s+=2;
        printf(" %d\n",s);
    }
    else{
        c =random()%2 +1;
        s+=c;
        printf(" %d\n",s);
    }
    return (s);
}